storBattery = new Vue({
	el: "#storBattery",
	data: {
		currentUser:'', // 当前用户信息
		parentObject:{},
		baseForm: {}, // 考虑到可能修改传入参数，所以要防止直接引用
		detectionList: [],
		deviceForm: {
			tableData: [] // 列表集合
		},
		// 部位信息
		partForm: {
			tableData: [] // 列表集合
		},
		weatherList:[],
		dailagList:[],
		
		fileList:[],
		
		list:[], //本次检查记录
		toolCheckAddEditVisible:false,
	},
	components:{
		processlog, // 流程日志	
	},
	created: function() {
		let _this = this
		_this.currentUser = JSON.parse(localStorage.getItem("neiosUser"))
		_this.parentObject = JSON.parse(localStorage.getItem("neiosGoDetail")).obj
		// 获取码表
		let dictCodes = 'WEATHER';
		let dict = mui.neiosCommon.queryDict(dictCodes, (data) => {
			if (data != '') {
				_this.weatherList = data.WEATHER;
			}
		})
		_this.getList()
	},
	methods: {
		// 周期码表转换
		cycleUnitChange (data) {
			return mui.neiosCommon.dictTransform(this.weatherList,data)
		},
		//获取列表
		getList(){
			let _this = this
			//网络安全列表
			let param = {
				"workId": this.parentObject.workId
			}
			mui.neiosRequst.httpRequst('/app/regularWork/infrared/getInfraredDetails', param,
				(data) => {
					if (data.code == '0') {
						_this.dealResultData(data.data);
					} else {
						mui.toast("获取数据错误：" + data.msg);
					}
				},
				(data) => {
					mui.toast("获取数据错误：" + data.msg);
				}
			);
		},
		// 返回值处理
		dealResultData(data) {
			// 基本信息
			this.baseForm = data[0];
			// 设备红外检测记录
			let detectionIds = [];
			if (data.length > 0) {
				detectionIds = [data[0].infraredDetectionId];
				this.detectionList = (data[0].infraredDetectionId == null ? [] : [data[0]]).concat(data.filter((item, index, arr) => {
					let itIdNotIn = detectionIds.indexOf(item.infraredDetectionId) == -1;
					if (itIdNotIn) {
						detectionIds.push(item.infraredDetectionId);
					}
					return index > 0 && itIdNotIn;
				})).map((item, index) => {
					item.dtcMonthDay = this.getTime(new Date(item.dtcDate), 'day').substr(5).replace('-', '月') + '日';
					return item;
				});
			}
			// 被检测设备信息
			let deviceIds = [];
			if (data.length > 0) {
				deviceIds = [data[0].infraredDeviceId];
				this.deviceForm.tableData = (data[0].infraredDeviceId == null ? [] : [data[0]]).concat(data.filter((item, index,
					arr) => {
					let itIdNotIn = deviceIds.indexOf(item.infraredDeviceId) == -1;
					if (itIdNotIn) {
						deviceIds.push(item.infraredDeviceId);
					}
					return index > 0 && itIdNotIn;
				}));
			}
			// 被检测部位信息
			let partIds = [];
			if (data.length > 0) {
				partIds = [data[0].infraredPartId];
				this.partForm.tableData = (data[0].infraredPartId == null ? [] : [data[0]]).concat(data.filter((item, index, arr) => {
					let itIdNotIn = partIds.indexOf(item.infraredPartId) == -1;
					if (itIdNotIn) {
						partIds.push(item.infraredPartId);
					}
					return index > 0 && itIdNotIn;
				}));
			}
			// 根据检测日期排序
			this.detectionList.sort((a, b) => new Date(b.dtcDate).getTime() - new Date(a.dtcDate).getTime());
		},
		// 查看详情
		upToolCheckDialogFn (item) {
			for (let a=0; a < this.partForm.tableData.length;a++) {
				if (this.partForm.tableData[a].infraredDeviceId == item.infraredDeviceId && this.partForm.tableData[a].dataStatus != '0') {
					this.dailagList.push(this.partForm.tableData[a])
				}
			}
			console.log(JSON.stringify(this.dailagList))
			this.toolCheckAddEditVisible = true
		},
		// 关闭
		closeToolCheckAddEdit () {
			this.toolCheckAddEditVisible = false
			this.dailagList = []
		},
		//获取时间
		getTime(myDate, type) {
			var realYear = myDate.getFullYear();
			var myMonth = myDate.getMonth() + 1;
			var realMonth = myMonth;
			var myDay = myDate.getDate();
			var realDay = myDay;
			var myHour = myDate.getHours();
			var realHours = myHour;
			var myMinute = myDate.getMinutes();
			var realMinute = myMinute;
			var mySecond = myDate.getSeconds();
			var realSecond = mySecond;
			if (myMonth < 10) {
				realMonth = "0" + myMonth;
			}
			if (myDay < 10) {
				realDay = "0" + myDay;
			}
			if (myMinute < 10) {
				realMinute = "0" + myMinute;
			}
			if (myHour < 10) {
				realHours = "0" + myHour;
			}
			if (mySecond < 10) {
				realSecond = "0" + mySecond;
			}
			var realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' +
				realSecond;
			if (type == "sec") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' + realSecond;
			} else if (type == "min") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute;
			} else if (type == "hour") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours;
			} else if (type == "day") {
				realDate = realYear + '-' + realMonth + '-' + realDay;
			} else if (type == "month") {
				realDate = realYear + '-' + realMonth;
			} else if (type == "year") {
				realDate = realYear;
			}
			return realDate;
		},
		
		
		// 返回
		goBack () {
			mui.back()
		}
	}
});